using Game.Main.Model;
using UnityEngine;

namespace Game.Component
{
	public class CarToolItem : BaseItem
	{
		private Transform tool;

		private float counter;

		private bool isAdd;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			tool = model.Find("Tool");
		}

		protected override void LateUpdate()
		{
			base.LateUpdate();
			if (!isDrag)
			{
				return;
			}
			if (isAdd)
			{
				counter += Time.deltaTime * 4f;
				if (counter >= 1f)
				{
					counter = 1f;
					isAdd = false;
				}
			}
			else
			{
				counter -= Time.deltaTime * 4f;
				if (counter <= -1f)
				{
					counter = -1f;
					isAdd = true;
				}
			}
			tool.localEulerAngles = new Vector3(0f, 0f, 15f * counter);
		}

		public override void TouchDown(TouchEventData touchEventData)
		{
			base.TouchDown(touchEventData);
			counter = 0f;
			isAdd = true;
		}

		public override void TouchUp(TouchEventData touchEventData)
		{
			base.TouchUp(touchEventData);
			tool.localEulerAngles = new Vector3(0f, 0f, 0f);
		}
	}
}
